package com.wms.service.impl;

import com.wms.entity.Authority;
import com.wms.mapper.AuthorityMapper;
import com.wms.service.AuthorityService;
import com.wms.service.ResourceAuthorityService;
import io.jsonwebtoken.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AuthorityServiceImpl extends BaseServiceImpl<AuthorityMapper, Authority> implements AuthorityService {


    @Resource
    private AuthorityMapper authorityMapper;

    @Autowired
    private ResourceAuthorityService resourceAuthorityService;


    @Override
    @Transactional
    public void deleteById(Long id) {
        Assert.notNull(id);
        // 删除权限
        authorityMapper.deleteById(id);
        // 删除资源
        resourceAuthorityService.deleteByAuthorityId(id);
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        Assert.notEmpty(ids);
        // 删除权限
        authorityMapper.deleteBatchIds(ids);
        // 删除资源s
        resourceAuthorityService.deleteByAuthorityIds(ids);
    }

    @Override
    public List<Authority> findByAdminId(Long adminId) {
        if (adminId == null) return null;
        return authorityMapper.findByAdminId(adminId);
    }
}
